﻿package com.curlyben.events {
	import com.curlyben.net.HTTPHeader;
	import com.curlyben.net.HTTPRequest;
	import flash.events.Event;
	import flash.net.URLRequest;
	import flash.utils.ByteArray;
	
	/**
	* ...
	* @author Default
	*/
	public class HTTPEvent extends Event{
		
		public static const EV_PREMATUREDISCONNECT	:String = "prematureDisconnect";
		public static const EV_CONNECTED			:String = "connected";
		
		public static const EV_HEADERCOMPLETE		:String = "headerComplete";
		public static const EV_DATAPROGRESS			:String = "dataProgress";
		public static const EV_DATACOMPLETE			:String = "dataComplete";
		
		// TODO: Add meta for ASDoc
		
		private var pRequest:HTTPRequest;
		public function get Request():HTTPRequest {
			return pRequest;
		}
		
		public function get HeaderBytesTotal():uint {
			return pRequest.RawHeader.length;
		}
		
		public function get DataBytesLoaded():uint {
			return pRequest.ResponseData.length;
		}
		
		public function get DataBytesTotal():int {
			var p:HTTPHeader = pRequest.GetHeader("content-length");
			if (p.Value.length < 1)
				return -1;
			return parseInt(p.Value);
		}
		
		public function HTTPEvent(etype:String, request:HTTPRequest = null, ebubbles:Boolean = false, ecancelable:Boolean = false) {
			super(etype);
			pRequest = request;
		}
	}
	
}